package com.itheima.d3_ExecutorsUtil;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 使用工具类直接得到线程对象
 */

public class ExecutorsDemo {
    public static void main(String[] args) {
        //1. 使用NewFixedThread
        ExecutorService pool = Executors.newFixedThreadPool(3);
        Runnable runnable = new MyRunnable();
        pool.execute(runnable);
        pool.execute(runnable);
        pool.execute(runnable);
        //此时没有多余的线程
        pool.execute(runnable);
    }
}
class MyRunnable implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName()+":"+i);
        }
        try {
            System.out.println(Thread.currentThread().getName()+"：任务线程绑定进入休眠");
            Thread.sleep(100000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}